home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_gimp.idb / usr / freeware / share / gimp / scripts / beveled-button.scm.z / beveled-button.scm
Encoding:
Text File  |  1999-07-21  |  5.0 KB  |  186 lines

  1. ; The GIMP -- an image manipulation program
  2. ; Copyright (C) 1995 Spencer Kimball and Peter Mattis
  3. ; Button00 --- create a simple beveled Web button
  4. ; Copyright (C) 1997 Federico Mena Quintero
  5. ; federico@nuclecu.unam.mx
  6. ; This program is free software; you can redistribute it and/or modify
  7. ; it under the terms of the GNU General Public License as published by
  8. ; the Free Software Foundation; either version 2 of the License, or
  9. ; (at your option) any later version.
  10. ; This program is distributed in the hope that it will be useful,
  11. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. ; GNU General Public License for more details.
  14. ; You should have received a copy of the GNU General Public License
  15. ; along with this program; if not, write to the Free Software
  16. ; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  
  18.  
  19. (define (text-width extents)
  20.   (car extents))
  21.  
  22. (define (text-height extents)
  23.   (cadr extents))
  24.  
  25. (define (text-ascent extents)
  26.   (caddr extents))
  27.  
  28. (define (text-descent extents)
  29.   (cadr (cddr extents)))
  30.  
  31. (define (blend-bumpmap img drawable x1 y1 x2 y2)
  32.   (gimp-blend img
  33.           drawable
  34.           FG-BG-RGB
  35.           DARKEN-ONLY
  36.           LINEAR
  37.           100
  38.           0
  39.           REPEAT-NONE
  40.           FALSE
  41.           0
  42.           0
  43.           x1
  44.           y1
  45.           x2
  46.           y2))
  47.  
  48. (define (script-fu-button00 text
  49.                 size
  50.                 foundry
  51.                 family
  52.                 weight
  53.                 slant
  54.                 set-width
  55.                 spacing
  56.                 ul-color
  57.                 lr-color
  58.                 text-color
  59.                 padding
  60.                 bevel-width
  61.                 pressed)
  62.   (let* ((old-fg-color (car (gimp-palette-get-foreground)))
  63.      (old-bg-color (car (gimp-palette-get-background)))
  64.      
  65.      (text-extents (gimp-text-get-extents text
  66.                           size
  67.                           PIXELS
  68.                           foundry
  69.                           family
  70.                           weight
  71.                           slant
  72.                           set-width
  73.                           spacing))
  74.      (ascent (text-ascent text-extents))
  75.      (descent (text-descent text-extents))
  76.      
  77.      (img-width (+ (* 2 (+ padding bevel-width))
  78.                (- (text-width text-extents)
  79.               (text-width (gimp-text-get-extents " "
  80.                                  size
  81.                                  PIXELS
  82.                                  foundry
  83.                                  family
  84.                                  weight
  85.                                  slant
  86.                                  set-width
  87.                                  spacing)))))
  88.      (img-height (+ (* 2 (+ padding bevel-width))
  89.             (+ ascent descent)))
  90.  
  91.      (img (car (gimp-image-new img-width img-height RGB)))
  92.  
  93.      (bumpmap (car (gimp-layer-new img img-width img-height RGBA_IMAGE "Bumpmap" 100 NORMAL)))
  94.      (gradient (car (gimp-layer-new img img-width img-height RGBA_IMAGE "Gradient" 100 NORMAL))))
  95.  
  96.     (gimp-image-disable-undo img)
  97.  
  98.     ; Create bumpmap layer
  99.     
  100.     (gimp-image-add-layer img bumpmap -1)
  101.     (gimp-palette-set-foreground '(0 0 0))
  102.     (gimp-palette-set-background '(255 255 255))
  103.     (gimp-edit-fill img bumpmap)
  104.  
  105.     (gimp-rect-select img 0 0 bevel-width img-height REPLACE FALSE 0)
  106.     (blend-bumpmap img bumpmap 0 0 (- bevel-width 1) 0)
  107.  
  108.     (gimp-rect-select img 0 0 img-width bevel-width REPLACE FALSE 0)
  109.     (blend-bumpmap img bumpmap 0 0 0 (- bevel-width 1))
  110.  
  111.     (gimp-rect-select img (- img-width bevel-width) 0 bevel-width img-height REPLACE FALSE 0)
  112.     (blend-bumpmap img bumpmap (- img-width 1) 0 (- img-width bevel-width) 0)
  113.  
  114.     (gimp-rect-select img 0 (- img-height bevel-width) img-width bevel-width REPLACE FALSE 0)
  115.     (blend-bumpmap img bumpmap 0 (- img-height 1) 0 (- img-height bevel-width))
  116.  
  117.     (gimp-selection-none img)
  118.  
  119.     ; Create gradient layer
  120.  
  121.     (gimp-image-add-layer img gradient -1)
  122.     (gimp-palette-set-foreground ul-color)
  123.     (gimp-palette-set-background lr-color)
  124.     (gimp-blend img
  125.         gradient
  126.         FG-BG-RGB
  127.         NORMAL
  128.         LINEAR
  129.         100
  130.         0
  131.         REPEAT-NONE
  132.         FALSE
  133.         0
  134.         0
  135.         0
  136.         0
  137.         (- img-width 1)
  138.         (- img-height 1))
  139.  
  140.     (plug-in-bump-map 1 img gradient bumpmap 135 45 bevel-width 0 0 0 0 TRUE pressed 0)
  141.  
  142.     ; Create text layer
  143.  
  144.     (gimp-palette-set-foreground text-color)
  145.     (let ((textl (car (gimp-text
  146.                img -1 0 0 text 0 TRUE size PIXELS foundry family weight slant set-width spacing))))
  147.       (gimp-layer-set-offsets textl
  148.                   (+ bevel-width padding)
  149.                   (+ bevel-width padding descent)))
  150.  
  151.     ; Done
  152.  
  153.     (gimp-selection-none img)
  154.     (gimp-palette-set-foreground old-fg-color)
  155.     (gimp-palette-set-background old-bg-color)
  156.     (gimp-image-enable-undo img)
  157.     (gimp-display-new img)))
  158.  
  159. ; Register!
  160.  
  161. (script-fu-register "script-fu-button00"
  162.             "<Toolbox>/Xtns/Script-Fu/Buttons/Simple beveled button"
  163.             "Simple beveled button"
  164.             "Federico Mena Quintero"
  165.             "Federico Mena Quintero"
  166.             "June 1997"
  167.             ""
  168.             SF-VALUE "Text" "\"Hello world!\""
  169.             SF-VALUE "Size" "16"
  170.             SF-VALUE "Foundry" "\"adobe\""
  171.             SF-VALUE "Family" "\"helvetica\""
  172.             SF-VALUE "Weight" "\"bold\""
  173.             SF-VALUE "Slant" "\"r\""
  174.             SF-VALUE "Set width" "\"normal\""
  175.             SF-VALUE "Spacing" "\"p\""
  176.             SF-COLOR "Upper-left color" '(0 255 127)
  177.             SF-COLOR "Lower-right color" '(0 127 255)
  178.             SF-COLOR "Text color" '(0 0 0)
  179.             SF-VALUE "Padding" "2"
  180.             SF-VALUE "Bevel width" "4"
  181.             SF-VALUE "Pressed?" "FALSE")
  182.